package com.stars.empoly.fragment

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.stars.empoly.adapter.WithListAdapter
import com.stars.empoly.base.MBRFragment
import com.stars.empoly.config.ConfigRx
import com.stars.empoly.databinding.FragmentWithListBinding
import com.stars.empoly.model.DriverProfit
import com.stars.empoly.vmodel.WithListVModel
import com.trailer.base.net.IResp

/**
 *on 2021/5/9
 */
class WithListFragment : MBRFragment<WithListVModel, WithListAdapter, FragmentWithListBinding>(){

    override fun vmClass(): Class<WithListVModel> {
        return WithListVModel::class.java
    }

    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentWithListBinding {
       return FragmentWithListBinding.inflate(layoutInflater)
    }

    override fun initAdapter(): WithListAdapter {
        return WithListAdapter(vm)
    }
    override fun onListReceive(res: IResp<*>) {
        super.onListReceive(res)

        if (null != res) {

            var list = res.data() as List<DriverProfit>
            if (list.isEmpty() && vm.repository().page == 1) {

                binding.listEmpty.visibility = View.VISIBLE
            } else {
                binding.listEmpty.visibility = View.GONE
            }

        }
    }


    override fun title(): String? {
        return null
    }

    override val isRxbus: Boolean
        get() =true

    @Subscribe(tags = [Tag(ConfigRx.REFRESH_MONEY)])
    fun setRefreshMoney(position: String) {
        onRefresh()
    }
}
